package com.ecr.hub.database.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import com.ecr.hub.model.rail.Rail;
import com.ecr.hub.model.rail.TypeBundle;

public class MapperRail {

	protected static ParameterizedRowMapper<Rail> mapperRail = new ParameterizedRowMapper<Rail>() {
		public Rail mapRow(ResultSet rs, int rowNum) throws SQLException {
			Rail rail = new Rail();
			rail.setId(rs.getInt("id"));
			rail.setNumber(rs.getString("number"));
			rail.setAssignment(rs.getString("assignment"));
			rail.setComment(rs.getString("comment"));
			rail.setElectrical(rs.getString("electric_traction"));
			rail.setActive(rs.getBoolean("active"));
			rail.setLabel(rs.getString("label"));
			rail.setSortOrder(rs.getInt("sort_order"));
			rail.setUtilLength(rs.getInt("util_lenght"));
			rail.setCalcUtilLength(rs.getInt("util_lenght"));
			rail.setAvailable(rs.getBoolean("available"));
			// Pour simplifier les requêtes pas de OUTER JOIN.
			rail.setDestinationId(rs.getInt("destination_id"));
			rail.setDestinationLabel(rs.getString("destination_label"));
			rail.setDestinationHexColor(rs.getString("destination_hex_color"));

			TypeBundle bundle = new TypeBundle();
			bundle.setId(rs.getInt("bundle_id"));
			bundle.setLabel(rs.getString("bundle_label"));
			rail.setTypeBundle(bundle);
			return rail;
		}
	};

	protected static ParameterizedRowMapper<TypeBundle> mapperBundle = new ParameterizedRowMapper<TypeBundle>() {
		public TypeBundle mapRow(ResultSet rs, int rowNum) throws SQLException {
			TypeBundle bundle = new TypeBundle();
			bundle.setId(rs.getInt("id"));
			bundle.setLabel(rs.getString("label"));
			return bundle;
		}
	};
}
